package com.fernfx.xingtan.my.presenter;

import com.fernfx.xingtan.common.base.BaseEntity;
import com.fernfx.xingtan.common.base.BaseIRequestCallback;
import com.fernfx.xingtan.common.base.BaseView;
import com.fernfx.xingtan.common.network.IRequestCallback;
import com.fernfx.xingtan.common.network.entity.NetworkOKResult;
import com.fernfx.xingtan.my.contract.UpdatePwdContract;
import com.fernfx.xingtan.my.model.UpdatePwdModel;
import com.fernfx.xingtan.utils.FastJsonUtil;
import com.fernfx.xingtan.utils.OtherUtil;
import com.fernfx.xingtan.utils.ToastUtil;

import java.util.Map;

import io.rong.imlib.IFwLogCallback;

/**
 * Created by admin on 2018/8/16.
 */

public class UpdatePwdPresenter<P extends UpdatePwdContract.View> extends BaseIRequestCallback implements UpdatePwdContract.Presenter {
    private P P;
    private UpdatePwdContract.Model model;

    @Override
    public void init(BaseView view) {
        P = (P)view;
        this.model = new UpdatePwdModel();
    }

    @Override
    public void request(Map<String, Object> requestArgsMap) {
        model.request(requestArgsMap,this);
    }

    @Override
    public void detachView() {
        if (null != model) {
            model = null;
        }
    }

    @Override
    public void onSuccessful(NetworkOKResult result) {
        String message = result.getMessage();
        //判断是否修改密码成功
        BaseEntity baseEntity = FastJsonUtil.fromBean(message, BaseEntity.class);
        if (OtherUtil.checkRequestStatus(baseEntity)) {
            ToastUtil.showCentertoast("密码已修改");
            P.getActivity().finish();
        }else {
            ToastUtil.showCentertoast(baseEntity.getMsg());
        }
    }
}
